package com.auth.leaves.controller;

import com.auth.leaves.pojo.vo.SaveUser;
import com.auth.leaves.response.ResponseDataUtil;
import com.auth.leaves.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author: LEAVES
 * @Date: 2020年10月27日 17时33分01秒
 * @Version 1.0
 * @Description:
 */
@Slf4j
@RestController
@CrossOrigin
@RequestMapping("/api")
@Api(value = "用户信息管理")
public class UserController {

    @Resource
    private IUserService userService;

    /**
     * 查询全部用户
     * @param request
     * @param response
     * @return
     */
    @ApiOperation(value = "获取用户信息", notes = "获取全部用户信息")
//    @ApiResponses(names= {"code","msg","token","data"},values= {"状态码","消息","令牌","数据"})
    @RequestMapping(value = "/users", method = RequestMethod.GET)
    public Object queryAll(HttpServletRequest request, HttpServletResponse response){
        return userService.queryAll(request, response);
    }

    /**
     * 新增用户
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/users", method = RequestMethod.POST)
    public Object save(SaveUser saveUser, HttpServletRequest request, HttpServletResponse response){
        String authorization = request.getHeader("Authorization").substring(7);
        System.out.println("token = " + authorization);
        System.out.println("saveUser = " + saveUser.toString());
        //暂未实现
        return ResponseDataUtil.success("添加成功！");
    }
}
